from datetime import datetime
from pydantic import BaseModel


class Token(BaseModel):
    access_token: str
    token_type: str


class TokenData(BaseModel):
    username: str | None = None


class UserBase(BaseModel):
    username: str
    full_name: str | None = None


class UserCreate(UserBase):
    password: str


class User(UserBase):
    id: int
    is_admin: bool
    created_at: datetime

    class Config:
        orm_mode = True


class LibraryBase(BaseModel):
    name: str


class LibraryCreate(LibraryBase):
    pass


class Library(LibraryBase):
    id: int
    invite_code: str
    owner_id: int
    is_active: bool
    created_at: datetime

    class Config:
        orm_mode = True


class BookBase(BaseModel):
    isbn: str
    title: str
    author: str


class BookCreate(BookBase):
    cover_url: str | None = None


class Book(BookBase):
    id: int
    cover_url: str | None
    status: int
    added_by: int
    added_at: datetime

    class Config:
        orm_mode = True


class BorrowRecordBase(BaseModel):
    book_id: int
    borrower_id: int


class BorrowRecordCreate(BorrowRecordBase):
    pass


class BorrowRecord(BorrowRecordBase):
    id: int
    lender_id: int | None
    borrow_date: datetime
    return_date: datetime | None
    status: int

    class Config:
        orm_mode = True
